package org.apache.rocketmq.client.java.impl;

import apache.rocketmq.v2.*;
import com.google.common.util.concurrent.AbstractIdleService;
import com.google.common.util.concurrent.ListenableFuture;
import io.grpc.Metadata;
import io.grpc.stub.StreamObserver;
import org.apache.rocketmq.client.java.clientapis.ClientException;
import org.apache.rocketmq.client.java.route.Endpoints;
import org.apache.rocketmq.client.java.rpc.RpcInvocation;

import java.time.Duration;
import java.util.Iterator;
import java.util.concurrent.ScheduledExecutorService;

/**
 * @课程描述:从零带你写框架系列中的课程，整个系列包含netty，xxl-job，rocketmq，nacos，sofajraft，spring，springboot，disruptor，编译器，虚拟机等等。
 * @author：陈清风扬，个人微信号：chenqingfengyangjj。
 * @date:2025/6/10
 * @方法描述：客户端管理器接口
 */
public abstract class ClientManager extends AbstractIdleService {

    public abstract ScheduledExecutorService getScheduler();

    public abstract ListenableFuture<RpcInvocation<QueryRouteResponse>> queryRoute(Endpoints endpoints,
                                                                                   Metadata metadata, QueryRouteRequest request, Duration duration);
    public abstract ListenableFuture<RpcInvocation<HeartbeatResponse>> heartbeat(Endpoints endpoints,
                                                                                 Metadata metadata, HeartbeatRequest request, Duration duration);
    public abstract ListenableFuture<RpcInvocation<SendMessageResponse>> sendMessage(Endpoints endpoints,
                                                                                     Metadata metadata, SendMessageRequest request, Duration duration);
    public abstract ListenableFuture<RpcInvocation<QueryAssignmentResponse>> queryAssignment(Endpoints endpoints,
                                                                                             Metadata metadata, QueryAssignmentRequest request, Duration duration);
    public abstract ListenableFuture<RpcInvocation<Iterator<ReceiveMessageResponse>>> receiveMessage(
            Endpoints endpoints, Metadata metadata, ReceiveMessageRequest request, Duration duration);

    public abstract ListenableFuture<RpcInvocation<AckMessageResponse>> ackMessage(Endpoints endpoints,
                                                                                   Metadata metadata, AckMessageRequest request, Duration duration);
    public abstract ListenableFuture<RpcInvocation<ChangeInvisibleDurationResponse>> changeInvisibleDuration(
            Endpoints endpoints, Metadata metadata, ChangeInvisibleDurationRequest request, Duration duration);

    public abstract ListenableFuture<RpcInvocation<ForwardMessageToDeadLetterQueueResponse>>
    forwardMessageToDeadLetterQueue(Endpoints endpoints, Metadata metadata,
                                    ForwardMessageToDeadLetterQueueRequest request, Duration duration);

    public abstract ListenableFuture<RpcInvocation<EndTransactionResponse>> endTransaction(Endpoints endpoints,
                                                                                           Metadata metadata, EndTransactionRequest request, Duration duration);
    @SuppressWarnings("UnusedReturnValue")
    public abstract ListenableFuture<RpcInvocation<NotifyClientTerminationResponse>> notifyClientTermination(
            Endpoints endpoints, Metadata metadata, NotifyClientTerminationRequest request, Duration duration);

    public abstract StreamObserver<TelemetryCommand> telemetry(Endpoints endpoints, Metadata metadata,
                                                               Duration duration, StreamObserver<TelemetryCommand> responseObserver) throws ClientException;
}

